import { defineStore } from 'pinia'
import $ajax from '@/ajax/admin_ajax.js'
//
const controller = '/role'

const useRoleStore = defineStore('role', {
  state: () => {
    return {
      roles: [],
      role: {},
      drawer: false,
      clearTree: new Date().getTime()
    }
  },
  // 定义计算属性
  getters: {
    loadeditems(state) {
      return state.roles
    }
  },
  actions: {
    async auth4Role(sysids) {
      const path = controller + '/m/auth4role/byid/' + this.role.roleid
      const { data: res } = await $ajax.put(path, sysids)
      console.log(res)
    },
    showDrawer(row) {
      this.role = JSON.parse(JSON.stringify(row))
      this.clearTree = new Date().getTime()
      console.log(this.clearTree)

      this.drawer = !this.drawer
    },
    async modItem(row) {
      const path = controller + '/m/role/byid'
      row = JSON.parse(JSON.stringify(row))
      const { data: res } = await $ajax.put(path, row)
      console.log(res)
    },
    async findAll() {
      //
      const path = controller + '/q/findall/role'
      const { data: res } = await $ajax.get(path)
      if (res.code === 200) {
        this.roles = res.result
      }
    }
  }
})

export default useRoleStore
